<template>
  <div>
    <van-cell @click='popup=true' is-link :border='false' :value='cz.text'
              title='处置类型：'>
    </van-cell>
    <van-field
      v-model='json.carczMsg'
      rows='2'
      autosize
      label='处置内容'
      type='textarea'
      maxlength='300'
      border
      placeholder='请输入处置内容'
      show-word-limit
    />
    <van-popup position='bottom' v-model='popup'>
      <van-picker
        show-toolbar
        title='处置类型'
        :columns='columns'
        @confirm='onConfirm'
        ref='picker'
      />
    </van-popup>
    <div class='bottom'>
      <van-button block type='info' :loading='loading' @click='onSubmit'>确认提交</van-button>
    </div>
  </div>
</template>

<script>
import { insertTlCz } from '@/api/gov/car_stop'

export default {
  name: 'disposal',
  data () {
    return {
      json: { carczMsg: '' },
      popup: false,
      data: {},
      loading: false,
      cz: { text: '', value: '' },
      columns: [
        { text: '社区处置', value: '1' },
        { text: '服务驿站处置', value: '2' },
        { text: '宾馆处置', value: '3' },
        { text: '当日离沈', value: '9' },
        { text: '其他', value: '4' }
      ]
    }
  },
  mounted () {
    this.data = JSON.parse(this.$route.query.data)
  },
  methods: {
    onConfirm (x) {
      this.cz = x
      this.popup = false
    },
    onSubmit () {
      this.loading = true
      this.json.on_time = this.data.on_time
      this.json.BRANUM = this.data.BRANUM
      this.json.BRACOLOR = this.data.BRACOLOR
      this.json.type = this.cz.value
      if (!this.cz.value) {
        this.loading = false
        this.$toast.fail('未选择处置类型')
        return
      }
      insertTlCz(this.json).then(ret => {
        if (ret.data.errcode === 0) {
          this.$toast.success('处置成功')
          setTimeout(item => {
            this.loading = false
            if (this.$route.query.go == 2) {
              this.$router.go(-2)
            } else {
              this.$router.back()
            }
          }, 1500)
        } else {
          this.loading = false
          this.$toast.fail(ret.data.errmsg)
        }
      })
    },
    toPage (data) {
      /// this.$store.state.stopData
      this.$router.push({ name: 'car_stop_disposal', query: { data: JSON.stringify(data) } })
    }
  }
}
</script>

<style scoped>
.bottom {
  position: fixed;
  width: 90%;
  bottom: 30px;
  margin: auto;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

</style>
